// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.raknet;

import java.util.ArrayList;
import zombie.radio.devices.DeviceData;

public class VoiceManagerData {
    public static ArrayList<VoiceManagerData> data = new ArrayList();
    public long userplaychannel;
    public long userplaysound;
    public boolean userplaymute;
    public long voicetimeout;
    public final ArrayList<VoiceManagerData.RadioData> radioData = new ArrayList();
    public boolean isCanHearAll;
    short index;

    public VoiceManagerData(short _index) {
        this.userplaymute = false;
        this.userplaychannel = 0L;
        this.userplaysound = 0L;
        this.voicetimeout = 0L;
        this.index = _index;
    }

    public static VoiceManagerData get(short onlineId) {
        if (data.size() <= onlineId) {
            for (short _short = (short)data.size(); _short <= onlineId; _short++) {
                VoiceManagerData voiceManagerData0 = new VoiceManagerData(_short);
                data.add(voiceManagerData0);
            }
        }

        VoiceManagerData voiceManagerData1 = (VoiceManagerData)data.get(onlineId);
        if (voiceManagerData1 == null) {
            voiceManagerData1 = new VoiceManagerData(onlineId);
            data.set(onlineId, voiceManagerData1);
        }

        return voiceManagerData1;
    }

    public static class RadioData {
        DeviceData deviceData;
        public int freq;
        public float distance;
        public short x;
        public short y;
        float lastReceiveDistance;

        public RadioData(float _distance, float _x, float _y) {
            this(null, 0, _distance, _x, _y);
        }

        public RadioData(int _freq, float _distance, float _x, float _y) {
            this(null, _freq, _distance, _x, _y);
        }

        public RadioData(DeviceData data, float _x, float _y) {
            this(data, data.getChannel(), data.getMicIsMuted() ? 0.0F : (float)data.getTransmitRange(), _x, _y);
        }

        private RadioData(DeviceData deviceDatax, int _int, float float0, float float1, float float2) {
            this.deviceData = deviceDatax;
            this.freq = _int;
            this.distance = float0;
            this.x = (short)((int)float1);
            this.y = (short)((int)float2);
        }

        public boolean isTransmissionAvailable() {
            return this.freq != 0
                && this.deviceData != null
                && this.deviceData.getIsTurnedOn()
                && this.deviceData.getIsTwoWay()
                && !this.deviceData.isNoTransmit()
                && !this.deviceData.getMicIsMuted();
        }

        public boolean isReceivingAvailable(int channel) {
            return this.freq != 0
                && this.deviceData != null
                && this.deviceData.getIsTurnedOn()
                && this.deviceData.getChannel() == channel
                && this.deviceData.getDeviceVolume() != 0.0F
                && !this.deviceData.isPlayingMedia();
        }

        public DeviceData getDeviceData() {
            return this.deviceData;
        }
    }

    public static enum VoiceDataSource {
        Unknown,
        Voice,
        Radio,
        Cheat;
    }
}
